 <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>H+ 后台主题UI框架 - 基础表格</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/font-awesome.min.css" rel="stylesheet">
    <link href="__PUBLIC__/H+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__PUBLIC__/H+/css/animate.min.css" rel="stylesheet">
    <link href="__PUBLIC__/H+/css/style.min.css" rel="stylesheet">
	<script type="text/javascript">
		function del(){
		   if (confirm("真的要删除吗？删除后将无法找回！")){
		       return true;
		   }else{
		       return false;
		   }
		}
	</script>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加备份</h5>
                        <a href="{:U('index')}" class="btn btn-sm btn-primary pull-right m-t-n-xs">返回</a>
                    </div>
                    <div class="ibox-content">
						<div class="row">
                            <div class="col-sm-4 m-b-xs">
								<button type="button" id="export" class="btn btn-primary btn-sm" autocomplete="off">立即备份</button>
								<a id="optimize" class="btn btn-primary btn-sm" href="{:U('Database/optimize')}">优化表</a>
        						<a id="repair" class="btn btn-primary btn-sm" href="{:U('Database/repair')}">修复表</a>
                            </div>
                        </div>
						<form name="form" action="{:U('export')}" id="export-form" method="post" >
                            <table class="table  table-hover">
                                <thead>
                                    <th width="48"><input class="check-all" checked="chedked" type="checkbox" value=""></th>
                                    <th>表名</th>
                                    <th>数据量</th>
                                    <th>数据大小</th>
                                    <th>创建时间</th>
                                    <th>备份状态</th>
                                    <th>操作</th>
                                </thead>
                                <tbody>
									<volist name="list" id="table">
                                        <tr>
                                            <td class="num">
                                                <input class="ids" checked="chedked" type="checkbox" name="tables[]" value="{$table.name}">
                                            </td>
                                            <td>{$table.name}</td>
                                            <td>{$table.rows}</td>
                                            <td>{$table.data_length|format_bytes}</td>
                                            <td>{$table.create_time}</td>
                                            <td class="info">未备份</td>
                                            <td class="action">
                                                <a class="ajax-get no-refresh btn btn-primary btn-xs" href="{:U('Database/optimize?tables='.$table['name'])}">优化表</a>&nbsp;
                                                <a class="ajax-get no-refresh btn btn-primary btn-xs" href="{:U('Database/repair?tables='.$table['name'])}">修复表</a>
                                            </td>
                                        </tr>
                                    </volist>
										
                                </tbody>
                            </table>
						</form>
                    </div>
                </div>
            </div>
            
        </div>
        
    </div>

    <!-- 全局js -->
    <script src="__PUBLIC__/js/jquery.min.1.9.1.js"></script>
    <script src="__PUBLIC__/js/bootstrap.min.js"></script>



    <!-- Peity -->
    <script src="__PUBLIC__/H+/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- 自定义js -->
    <script src="__PUBLIC__/H+/js/content.min.js?v=1.0.0"></script>


    <!-- iCheck -->
    <script src="__PUBLIC__/H+/js/plugins/iCheck/icheck.min.js"></script>

    <!-- Peity -->
    <script src="__PUBLIC__/H+/js/demo/peity-demo.min.js"></script>

    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
	<script>
 		;$(function(){
			//全选的实现
			$(".check-all").click(function(){
				$(".ids").prop("checked", this.checked);
			});
			$(".ids").click(function(){
				var option = $(".ids");
				option.each(function(i){
					if(!this.checked){
						$(".check-all").prop("checked", false);
						return false;
					}else{
						$(".check-all").prop("checked", true);
					}
				});
			});
		
		});
    </script>
	<script type="text/javascript">

    (function($){
        var $form = $("#export-form"), $export = $("#export"), tables
            $optimize = $("#optimize"), $repair = $("#repair");
			
		

        $optimize.add($repair).click(function(){
            $.post(this.href, $form.serialize(), function(data){
                if(data.status){
                    alert(data.info,'alert-success');
                } else {
                	alert(data.info,'alert-error');
                }
                setTimeout(function(){
	                $('#top-alert').find('button').click();
	                $(that).removeClass('disabled').prop('disabled',false);
	            },1500);
            }, "json");
            return false;
        });

        $export.click(function(){
            $export.parent().children().addClass("disabled");
            $export.html("正在发送备份请求...");
            $.post(
                $form.attr("action"),
                $form.serialize(),
                function(data){
                    if(data.status){
                        tables = data.tables;
                        $export.html(data.info + "开始备份，请不要关闭本页面！");
                        backup(data.tab);
                        window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
                    } else {
                    	alert(data.info,'alert-error');
                        $export.parent().children().removeClass("disabled");
                        $export.html("立即备份");
                        setTimeout(function(){
        	                $('#top-alert').find('button').click();
        	                $(that).removeClass('disabled').prop('disabled',false);
        	            },1500);
                    }
                },
                "json"
            );
            return false;
        });

        function backup(tab, status){
            status && showmsg(tab.id, "开始备份...(0%)");
            $.get($form.attr("action"), tab, function(data){
                if(data.status){
                    showmsg(tab.id, data.info);

                    if(!$.isPlainObject(data.tab)){
                        $export.parent().children().removeClass("disabled");
                        $export.html("备份完成，点击重新备份");
                        window.onbeforeunload = function(){ return null }
                        return;
                    }
                    backup(data.tab, tab.id != data.tab.id);
                } else {
                    alert(data.info,'alert-error');
                    $export.parent().children().removeClass("disabled");
                    $export.html("立即备份");
                    setTimeout(function(){
    	                $('#top-alert').find('button').click();
    	                $(that).removeClass('disabled').prop('disabled',false);
    	            },1500);
                }
            }, "json");

        }

        function showmsg(id, msg){
            $form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
        }
    })(jQuery);
    </script>
    
    <!--统计代码，可删除-->

</body>

</html>